{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load Layer by Item ID\n",
    "\n",
    "This is the completed solution for the [Load Layer from an Item Tutorial](https://developers.arcgis.com/labs/data/python/add-a-layer-from-an-item/). \n",
    "\n",
    "[ArcGIS tutorials](https://developers.arcgis.com/labs/) are short guides demonstrating the three phases of building geospatial apps: Data, Design, Develop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from arcgis.gis import GIS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "trailheads_id = \"883cedb8c9fe4524b64d47666ed234a7\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "gis = GIS()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://www.arcgis.com/home/item.html?id=883cedb8c9fe4524b64d47666ed234a7' target='_blank'>\n",
       "                        <img src='https://www.arcgis.com/sharing/rest//content/items/883cedb8c9fe4524b64d47666ed234a7/info/thumbnail/ago_downloaded.png' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://www.arcgis.com/home/item.html?id=883cedb8c9fe4524b64d47666ed234a7' target='_blank'><b>Trailheads</b>\n",
       "                        </a>\n",
       "                        <br/><img src='https://www.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\">Feature Layer Collection by esri_devlabs\n",
       "                        <br/>Last Modified: October 09, 2017\n",
       "                        <br/>0 comments, 8,101 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Trailheads\" type:Feature Layer Collection owner:esri_devlabs>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trailheads_item = gis.content.get(trailheads_id)\n",
    "trailheads_item"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4eb64679c8024e31a1a94a9d3ea0a76c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MapView(jupyter_target='notebook', layout=Layout(height='400px', width='100%'), ready=True, zoom=11.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div class=\"map-static-img-preview-cfe173e3-609a-4608-8022-f2696392c765\"><img src=\"\"></img></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# For the ArcGIS API for JavaScript, we would order coordinates as [`longitude`, `latitude`]\n",
    "coords = [ -118.71511, 34.09042 ]\n",
    "\n",
    "# But for the ArcGIS API for Python, order coordinates as [`latitude`, `longitude`]\n",
    "coords.reverse()\n",
    "\n",
    "map.add_layer(trailheads_item)\n",
    "map.zoom = 11\n",
    "map.center = coords"
   ]
  }
 ],
 "metadata": {
  "esriNotebookRuntime": {
   "notebookRuntimeName": "ArcGIS Notebook Python 3 Standard",
   "notebookRuntimeVersion": "9.0"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
